<?php
/**
 * Created by PhpStorm.
 * User: Egg
 * Date: 2018/3/28
 * Time: 14:12
 */

namespace Admin\Model;


class UserLogic
{

    public function login($username, $password)
    {
        if (empty($username) || empty($password)) {
            \Common\Common\print_json_data(205, '', '账号和密码不能为空');
            exit;
        }
        $result = D('Admin')
            ->getByUsername($username);
        if (empty($result)) {
            \Common\Common\print_json_data(205, '', '账号或密码错误');
            exit;
        }
        if ($password != $result['password']) {
            \Common\Common\print_json_data(205, '', '账号或密码错误');
            exit;
        }
        session('uid', $result['id']);
        session('nickname', $result['nickname']);
        session('login_time', time());
        \Common\Common\print_json_data(200, '', '登入成功');
    }
}